package com.example.demo.service.impl;

import com.example.demo.bean.Goods;
import com.example.demo.bean.Goodsinfo;
import com.example.demo.dao.GoodsInfoMapper;
import com.example.demo.dao.GoodsMapper;
import com.example.demo.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsInfoMapper goodsInfoMapper;

    public List<Goods> queryGoodList(Goods goods){
        return goodsMapper.queryGoodList(goods);
    }

    @Override
    public Goods queryGood(int goodId) {
        Goods goods = goodsMapper.queryGood(goodId);
        if(goods!=null){
            List<Goodsinfo> goodsinfos = goodsInfoMapper.queryInfo(goods.getId());
            if (goodsinfos!=null)
            goods.setGoodsinfos(goodsinfos);
        }
        return goods;
    }

    @Override
    public Goods addGoods(Goods goods) {
        goodsMapper.addGoods(goods);
        return goods;
    }

    @Override
    public void updateGoods(Goods goods) {
        goodsMapper.updateGoods(goods);
    }

    @Override
    public int update(Goods goods) {
        return goodsMapper.update(goods);
    }


    @Override
    public int deleteGoods(int id) {
        return goodsMapper.deleteGoods(id);
    }


}
